//package tasko.main;
//test

import java.util.Vector;

//import java.util.Comparator;
public class Task implements Comparable<Task> {

    private static final int INITIALIZE_TASKID = -1;
    private static final String INITIALIZE_TASKTITLE = "";
    private static final String INITIALIZE_TASKDESCRIPTION = "";
    private static final String INITIALIZE_TASKSTARTDATE = "";
    private static final String INITIALIZE_TASKENDDATE = "";
    private static final boolean INITIALIZE_ISTASKSTARRED = false;
    private static final boolean INITIALIZE_ISTASKDONE = false;
    private static final TaskType INITIALIZE_TASKTYPE = TaskType.UNDEFINED;
    private static final int INITIALIZE_TASKSEARCHPRIORITY = -1;

    public enum TaskType {

        UNDEFINED, TIMEDTASK, DEADLINETASK, GENERALTASK
    }
    private int taskId;
    private String taskTitle;
    private String taskStartDate;
    private String taskEndDate;
    private String taskDescription;
    private boolean isTaskStarred;
    private TaskType taskType;
    private boolean isTaskDone;
    private int taskSearchPriority;
    private TaskAction taskAction;

    public enum TaskAction {

        UNDEFINED, ADD, DELETE, UPDATE, VIEW, SEARCH, UNDO, SYNC
    }

    public Task() {
        initializeMembers();
    }

    private void initializeMembers() {
        taskId = INITIALIZE_TASKID;
        taskTitle = INITIALIZE_TASKTITLE;
        taskStartDate = INITIALIZE_TASKSTARTDATE;
        taskEndDate = INITIALIZE_TASKENDDATE;
        setTaskDescription(INITIALIZE_TASKDESCRIPTION);
        isTaskStarred = INITIALIZE_ISTASKSTARRED;
        isTaskDone = INITIALIZE_ISTASKDONE;
        taskType = INITIALIZE_TASKTYPE;
        taskSearchPriority = INITIALIZE_TASKSEARCHPRIORITY;
    }

    /**
     *
     * @param taskId
     */
    public void setTaskId(int taskId) {
        this.taskId = taskId;
    }

    /**
     * @return taskId
     */
    public int getTaskId() {
        return this.taskId;
    }

    /**
     *
     * @param taskTitle
     */
    public void setTaskTitle(String taskTitle) {
        this.taskTitle = taskTitle;
    }

    /**
     *
     * @return taskTitle
     */
    public String getTaskTitle() {
        return this.taskTitle;
    }

    /**
     *
     * @param taskStartDate
     */
    public void setTaskStartDate(String taskStartDate) {
        this.taskStartDate = taskStartDate;
    }

    /**
     *
     * @return taskStartDate
     */
    public String getTaskStartDate() {
        return this.taskStartDate;
    }

    /**
     *
     * @param taskEndDate
     */
    public void setTaskEndDate(String taskEndDate) {
        this.taskEndDate = taskEndDate;
    }

    /**
     *
     * @return taskEndDate
     */
    public String getTaskEndDate() {
        return this.taskEndDate;
    }

    /**
     *
     * @param isTaskStarred
     */
    public void setIsTaskStarred(boolean isTaskStarred) {
        this.isTaskStarred = isTaskStarred;
    }

    /**
     *
     * @return true if it is a starred task
     */
    public boolean getIsTaskStarred() {
        return this.isTaskStarred;
    }

    /**
     *
     * @param isTaskDone
     */
    public void setIsTaskDone(boolean isTaskDone) {
        this.isTaskDone = isTaskDone;
    }

    /**
     *
     * @return true if task is done
     */
    public boolean getIsTaskDone() {
        return this.isTaskDone;
    }

    /**
     *
     * @param taskType
     */
    public void setTaskType(String taskType) {

        if (taskType == "UNDEFINED") {
            this.taskType = TaskType.UNDEFINED;
        } else if (taskType == "TIMEDTASK") {
            this.taskType = TaskType.TIMEDTASK;
        } else if (taskType == "DEADLINETASK") {
            this.taskType = TaskType.DEADLINETASK;
        } else if (taskType == "GENERALTASK") {
            this.taskType = TaskType.GENERALTASK;
        } else {
            this.taskType = TaskType.UNDEFINED;
        }
    }

    /**
     *
     * @return the taskType
     */
    public TaskType getTaskType() {
        return this.taskType;
    }

    /**
     *
     * @return Description of task
     */
    public String getTaskDescription() {
        return taskDescription;
    }

    /**
     *
     * @param taskDescription
     */
    public void setTaskDescription(String taskDescription) {
        this.taskDescription = taskDescription;
    }

    /**
     *
     * @return the search priority of task
     */
    public int getTaskSearchPriority() {
        return taskSearchPriority;
    }

    /**
     *
     * @param taskSearchPriority
     */
    //TODO: need to clearly define the use and need of taskSearchPriority
    public void setTaskSearchPriority(int taskSearchPriority) {
        this.taskSearchPriority = taskSearchPriority;
    }

    /**
     * @param compareTaskPriority
     * @return
     */
    //TODO: refactor/rename - Compare to not clear
    public int compareTo(Task compareTaskPriority) {

        int compareQuantity = ((Task) compareTaskPriority)
                .getTaskSearchPriority();
        return this.taskSearchPriority - compareQuantity;

    }

    /**
     * Returns the values of all the members as a vector of strings
     *
     * @return
     */
    public Vector<String> getTask() {

        Vector<String> items = new Vector<String>();

        items.add(taskId + "");
        items.add(taskTitle);
        items.add(taskStartDate);
        items.add(taskEndDate);
        items.add(taskDescription);
        //TODO:  need to refactor here. Extract the following to a new method - String: boolToString(boolean) 
        if (isTaskStarred == true) {
            items.add("true");
        } else {
            items.add("false");
        }
        items.add(taskType.toString());
        if (isTaskDone == true) {
            items.add("true");
        } else {
            items.add("false");
        }
        items.add(taskSearchPriority + "");
        return items;
    }

    /**
     *
     * @param taskAction
     */
    public void setTaskAction(TaskAction taskAction) {
        this.taskAction = taskAction;
    }

    /**
     *
     * @return
     */
    public TaskAction getTaskAction() {
        return this.taskAction;
    }

    public void doTask() {
        TaskOperations taskOperations = new TaskOperations(this, TaskO.taskList.tasksInTempStorage, TaskO.taskList.tasksOnDisplay, TaskO.taskList.typeTasksOnDisplay, TaskO.taskList.snapshotOfTasks);
    }
}